import request from '@/utils/request'
import { JsonData } from '@/api/meeting'

// 展商信息接口
export interface ExhibitorDO {
  id: number
  name: string           // 展商名称
  description: string    // 展商介绍
  imageUrl: string      // 展商图片
  videoUrl?: string     // 展商视频链接
}

// 展商列表请求参数
export interface ListExhibitorRequest {
  page: number
  size: number
  name?: string        // 展商名称搜索
}

// 展商列表响应
export interface ListExhibitorResponse {
  total_record: number
  total_page: number
  current_data: ExhibitorDO[]
}

/**
 * 获取展商列表
 * @param params 查询参数
 */
export const getExhibitorList = (params: ListExhibitorRequest) => {
  return request.post<any,ListExhibitorResponse>('/api/exhibitor/list', params)
}

/**
 * 获取展商详情
 * @param id 展商ID
 */
export const getExhibitor = (id: number) => {
  return request.get<ExhibitorDO>(`/api/exhibitor/${id}`)
}

/**
 * 上传展商图片
 * @param file 图片文件
 */
export const uploadExhibitorImage = (file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  return request.post<JsonData>('/api/exhibitor/upload_img', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 上传展商视频
 * @param file 视频文件
 */
export const uploadExhibitorVideo = (file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  return request.post<JsonData>('/api/exhibitor/upload_video', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 删除展商图片
 * @param exhibitorId 展商ID
 */
export const deleteExhibitorImage = (exhibitorId: number) => {
  return request.delete<JsonData>(`/api/exhibitor/${exhibitorId}/image`)
}

/**
 * 删除展商视频
 * @param exhibitorId 展商ID
 */
export const deleteExhibitorVideo = (exhibitorId: number) => {
  return request.delete<JsonData>(`/api/exhibitor/${exhibitorId}/video`)
}

/**
 * 添加展商
 * @param data 展商数据
 */
export const addExhibitor = (data: Partial<ExhibitorDO>) => {
  return request.post<JsonData>('/api/exhibitor/add', data)
}

/**
 * 更新展商
 * @param id 展商ID
 * @param data 更新的展商数据
 */
export const updateExhibitor = (id: number, data: Partial<ExhibitorDO>) => {
  return request.put<JsonData>(`/api/exhibitor/${id}`, data)
}

/**
 * 删除展商
 * @param id 展商ID
 */
export const deleteExhibitor = (id: number) => {
  return request.delete<JsonData>(`/api/exhibitor/${id}`)
}
 